<script setup lang="ts">
import { provide } from 'vue'
import elLocaleZhCN from 'element-plus/dist/locale/zh-cn'
import { uploadImage, uploadFile } from '@/api/other'
import type { UploadFile } from '@/components/x-components/x-upload-file/index.vue'

/** 提供x-upload组件默认的上传事件 */
provide('x-upload-image:defaultApi', (file: UploadFile) =>
	uploadImage(file.file!, (progressEvent) => {
		file.percent = Math.round((10000 * progressEvent.loaded) / progressEvent.total) / 100
	}).then((res) => res.data.url)
)
provide('x-upload-file:defaultApi', (file: UploadFile) =>
	uploadFile(file.file!, (progressEvent) => {
		file.percent = Math.round((10000 * progressEvent.loaded) / progressEvent.total) / 100
	}).then((res) => res.data.url)
)

/** 提供x-rich-editor组件自定义上传 */
provide('x-rich-editor:imageApi', (file: File) => uploadImage(file).then((res) => res.data.url))
provide('x-rich-editor:videoApi', (file: File) => uploadFile(file).then((res) => res.data.url))
</script>

<template>
	<el-config-provider :locale="elLocaleZhCN">
		<router-view></router-view>
	</el-config-provider>
</template>

<style></style>
